<?php echo $documentForm->renderGlobalErrors()?>
<?php echo $creditMemoForm->renderGlobalErrors()?>
<?php echo $documentForm['document_iden']?>
<?php echo $documentForm['_csrf_token']?>
<?php echo $creditMemoForm['credit_iden']?>
<?php echo $creditMemoForm['customer_iden']?>
<?php echo $creditMemoForm['invoice_iden']?>
<?php echo $creditMemoForm['_csrf_token']?>
<table class="form">
  <tr>
    <th class="field"><?php echo $documentForm['owner_iden']->renderLabel()?></th>
    <td>
      <?php echo $documentForm['owner_iden']->renderError()?>
      <?php echo $documentForm['owner_iden']?>
    </td>
  </tr>
  <tr>
    <th class="field"><?php echo $documentForm['counter_code']->renderLabel()?></th>
    <td>
      <?php echo $documentForm['counter_code']->renderError()?>
      <?php echo $documentForm['counter_code']?>
    </td>
  </tr>
  <tr>
    <th class="field"><?php echo $creditMemoForm['credit_type']->renderLabel()?></th>
    <td>
      <?php echo $creditMemoForm['credit_type']?>
      <?php echo $creditMemoForm['credit_number']->renderError()?>
      <?php echo $creditMemoForm['credit_number']?>
    </td>
  </tr>
  <tr>
    <th class="field"><?php echo $documentForm['document_date']->renderLabel()?></th>
    <td>
      <?php echo $documentForm['document_date']->renderError()?>
      <?php echo $documentForm['document_date']?>
    </td>
  </tr>
  <tr>
    <th class="field"><?php echo $creditMemoForm['remarks']->renderLabel()?></th>
    <td>
      <?php echo $creditMemoForm['remarks']->renderError()?>
      <?php echo $creditMemoForm['remarks']?>
    </td>
  </tr>
  <tr>
    <th class="field">Invoice#</th>
    <td>
        <?php echo $invoice->getInvoiceNumber();?>
    </td>
  </tr>
  <tr>
    <th class="field"><?php echo $creditMemoForm['amount']->renderLabel()?></th>
    <td>
      <?php echo $creditMemoForm['amount']->renderError()?>
      <?php echo $creditMemoForm['amount']?>
    </td>
  </tr>
  <tr>
    <th class="field"><?php echo $creditMemoForm['tax_code']->renderLabel()?></th>
    <td>
      <?php echo $creditMemoForm['tax_code']->renderError()?>
      <?php echo $creditMemoForm['tax_code']?>
    </td>
  </tr>
</table>


<script language="javascript">
  $(document).ready(function(){
    $('#credit_memo_credit_number').blur(function(){
      $.getJSON(
        'creditMemo/checkId',
        {
          "credit_iden":$('#credit_memo_credit_iden').val(),
          "credit_type":$('#credit_memo_credit_type').val(),
          "credit_number":$('#credit_memo_credit_number').val(),
        },
        function(data){
          if(data.count > 0){
            credit_id = $('#credit_memo_credit_type').val()+'-'+$('#credit_memo_credit_number').val();
            alert(credit_id+' already exists.');
          }
        }
      );
    });
  });
</script>